package com.daoxiang.service.impl;

import com.daoxiang.dao.GoodsMapper;
import com.daoxiang.pojo.Goods;
import com.daoxiang.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> queryGoods(Goods goods) {
        return goodsMapper.queryGoods(goods);
    }

    @Override
    public List<Goods> queryGoodsByKey(String gname) {
        return goodsMapper.queryGoodsByKey(gname);
    }

    @Override
    public int updateGoodById(Goods goods) {
        return goodsMapper.updateGoodById(goods);
    }

    @Override
    public int deleteGoodById(Integer gid) {
        return goodsMapper.deleteGoodById(gid);
    }

    @Override
    public int insertGood(Goods goods) {
        return goodsMapper.insertGood(goods);
    }

    @Override
    public List<Goods> queryGoodsByName(String searchValue) {
        Example example = new Example(Goods.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("gname",   "%"+searchValue+"%");
        return this.goodsMapper.selectByExample(example);
    }
}
